//
//  WBViewController.m
//  SunXi
//
//  Created by dllo on 15/12/7.
//  Copyright © 2015年 大远. All rights reserved.
//

#import "WBViewController.h"
#import "AppDelegate.h"

@interface WBViewController ()

@end

@implementation WBViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    AppDelegate *myDelegate =(AppDelegate*)[[UIApplication sharedApplication] delegate];
    
    WBAuthorizeRequest *authRequest = [WBAuthorizeRequest request];
    authRequest.scope = @"all";
    authRequest.redirectURI = kRedirectURI;
    
    WBSendMessageToWeiboRequest *request = [WBSendMessageToWeiboRequest requestWithMessage:[self messageToShare] authInfo:authRequest access_token:myDelegate.wbtoken];
    request.userInfo = @{@"ShareMessageFrom": @"SendMessageToWeiboViewController",
                         @"Other_Info_1": [NSNumber numberWithInt:123],
                         @"Other_Info_2": @[@"obj1", @"obj2"],
                         @"Other_Info_3": @{@"key1": @"obj1", @"key2": @"obj2"}};
    //    request.shouldOpenWeiboAppInstallPageIfNotInstalled = NO;
    [WeiboSDK sendRequest:request];

    
}

- (WBMessageObject *)messageToShare{
    WBMessageObject *message = [WBMessageObject message];
    NSString *shaStr;
    switch ([shareModel sharedInstance].type) {
        case Look: {
            shaStr = [NSString stringWithFormat:@"瞬息文章:%@链接:%@",[shareModel sharedInstance].title,[shareModel sharedInstance].code];
            break;
        }
        case Music: {
            NSDictionary *dic = [DyAFnetWorking convertStrToBodyDic:[shareModel sharedInstance].code];
            NSLog(@"%@",dic[@"url"]);
            
            shaStr = [NSString stringWithFormat:@"瞬息电台:%@链接:%@",[shareModel sharedInstance].title,dic[@"url"]];
            
            break;
        }
        case Movie: {
            shaStr = [NSString stringWithFormat:@"瞬息视频:%@链接:%@",[shareModel sharedInstance].title,[shareModel sharedInstance].code];
            
            break;
        }
        default: {
            break;
        }
    }
    message.text = shaStr;
    
    
    
    
    
    return message;
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
